package com.lvcoding.spring5.annotation3x.bean;

import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @Description 描述
 * @Date 2020-07-23 12:15 下午
 * @Author wuyanshen
 */
public class ConnectionBeanFactory implements FactoryBean<Connection> {
    @Override
    public Connection getObject() throws Exception {
        Connection connection = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mbtest?useSSL=false","root", "root");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return connection;
    }

    @Override
    public Class<?> getObjectType() {
        return Connection.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
